<template>
	<view>
		<u-sticky>
			<view class="u-padding-20" style="background: #FFFFFF;">
				<u-search placeholder="搜索商品" v-model="initial.parm.keyword" :animation="false" bg-color="#fff"
					border-color="#333" :show-action="false" @change="searchChange">
				</u-search>
			</view>
		</u-sticky>



		<view class="carblock" @click="gocar">
			<view style="position: relative;top: 10rpx;">
				<u-icon name="shopping-cart" :size="60"></u-icon>
				<u-badge class="car-num" :count="count" type="error" :offset="[-3, -6]"></u-badge>
			</view>
			<view>
				购物车
			</view>
		</view>

		<shopList v-if="list.length" :list="list" @go="go">

		</shopList>


		<u-loadmore :status="initial.status" />
	</view>
</template>

<script>
	import shopList from "@/components/shopList.vue";
	import loader from '@/common/loadPage.js';
	export default {
		mixins: [loader],
		components: {
			shopList,
		},
		data() {

			return {
				list: [],
				initial: {
					geturl: "/index/goods",
					parm: {
						goods_classify_id: "",
						keyword: "",
						goods_type: 1
					},
					isPage: true
				},
				count: ""
			}
		},
		onLoad(option) {
			if (option.id) {
				this.initial.parm.goods_classify_id = option.id;
			}
			if(option.keyword){
				this.initial.parm.keyword = option.keyword;
				this.$forceUpdate()
				
			}
			this.getGoods()
			
		},
		onShow() {
			this.carnum()
		},
		methods: {
			go(item) {
				uni.navigateTo({
					url: "./detail?id=" + item.id
				})
			},
			carnum() {
				this.$u.api.carNum().then(res => {
					this.count = res.cart
				})
			},
			gocar(){
				uni.navigateTo({
					url:"./car"
				})
			},
			searchChange(e){
				this.initial.parm.keyword = e;
				this.getGoods()
			}
		},
	}
</script>

<style>
	.carblock {
		position: fixed;

		height: 80rpx;
		right: 0;
		bottom: 200rpx;
		background: #FFFFFF;
		box-shadow: 0px 4rpx 6rpx rgba(209, 209, 209, 0.26);
		border-radius: 40rpx 0px 0px 40rpx;
		line-height: 80rpx;
		text-align: center;
		display: flex;
		align-items: center;
		padding: 0 20rpx;
	}
</style>
